/**
 * 系统后台多表夸库查询服务JS-SingleTableService.jsp
 */
var operation = {};
var postPath = '/gdp'
var app = new Vue({
    el: '#main-container',
    data: {

        optFlag: false,
        info: {
            //测站编码
            stcd: '',
            //测站名称
            stnm: '',
            //河流名称
            rvnm: '',
            //水系名称
            hnnm: '',
            //流域名称
            bsnm: '',
            //经度
            lgtd: '',
            //纬度
            lttd: '',
            //站址
            stlc: '',
            //行政区划码
            addvcd: '',
        }
    },
    computed: {},

    created: function () {

    },

    watch: {
        "relInfo.cfgMultRelation.firstServiceId": function (n, o) {
            // this.filed1List = this.getFieldList(n);
            this.resFiled1List = this.getResFieldList(n)
        },



        "info.lgtd": function (n, o) {
            let numbers = n.split('.');
            let zs = numbers[0];
            if (zs.length > 10) {
                showMsg("整数长度不能大于10位")
                return o;
            }
            let xs = numbers[1];
            if (xs && xs.length > 10) {
                showMsg("整数长度不能大于10位")
                return o;
            }
            return n;
        }
    },
    mounted: function () {
        this.initData();
    },
    methods: {
        /**
         * 初始化数据
         */
        initData() {
            // 操作类型
            let opt = this.getQueryString("opt");
            if (opt === 'edit') {
                this.optFlag = true;
                // 获取数据
                this.selectById();
            }
        },
        /**
         * 返回按钮
         */
        backBtn() {
            window.location.href = postPath + "/acStationInfo/index"
        },
        /**
         * 保存配置信息
         */
        saveCfgInfo() {
            let _this = this;
            // 操作类型
            let opt = _this.getQueryString("opt");
            let params = _this.info
            if (!params.stcd) {
                showMsg("站点编码不能为空!", "error");
                return;
            }
            params.optType = opt.toUpperCase();
            $.ajax({
                type: 'POST',
                url: postPath + '/accesscontrol/acStationInfo/save',
                data: JSON.stringify(params),
                dataType: 'json',
                async: false,
                contentType: 'application/json;charset=UTF-8',
                success: function (res) {
                    if (res.success) {
                        showMsg("操作成功!", "success");
                    } else {
                        showMsg(res.msg ? res.msg : '操作失败,请稍后重试!', "error");
                    }
                }
            });


        },
        /**
         * 查询配置
         */
        selectById() {
            let _this = this;
            // 主键
            let stcd = this.getQueryString("stcd");
            $.ajax({
                type: 'POST',
                url: postPath + '/accesscontrol/acStationInfo/selectById',
                data: JSON.stringify({stcd: stcd}),
                dataType: 'json',
                async: false,
                contentType: 'application/json;charset=UTF-8',
                success: function (res) {
                    if (res.success) {
                        _this.info = res.data;
                    } else {
                        showMsg("操作失败,请稍后重试!", "error");
                    }
                }
            });


        },
        
        
        stcdChange(stcd){
            let reg = new RegExp('^[^\u4e00-\u9fa5]+$');
            if (!reg.test(stcd)) {
                this.info.stcd = ''
                showMsg("测站编码不能为中文","error")
            }
        },

        //获取Query参数
        getQueryString: function (name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
            var r = window.location.search.substr(1).match(reg);
            if (r != null) return unescape(r[2]);
            return null;
        },
    }
})


function showMsg(text, icon) {
    $.toast().reset('all');
    $.toast({
        text: text,
        icon: icon,
        showHideTransition: 'fade',
        allowToastClose: true,
        hideAfter: 1500,
        stack: false,
        position: 'top-right',
        textAlign: 'left',
        loader: true,
        loaderBg: '#9ec600',
    });
}
